﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hongapo_Common;

public partial class sysadmin_Product_productlist : PageBase
{
    private Hongapo_Services.Product.Product bll = new Hongapo_Services.Product.Product();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindRepeter();
        }
    }

    private void BindRepeter()
    {
        int pageIndex = TypeConvert.ToInt32(Request["page"], 1);
        DataSet ds = bll.GetList(this.Pager.PageSize,pageIndex," 1=1");
        this.rptList.DataSource = ds.Tables[0];
        this.rptList.DataBind();
        if (ds.Tables[1]!=null && ds.Tables[1].Rows.Count>0)
        {
            this.Pager.RecordCount = TypeConvert.ToInt32(ds.Tables[1].Rows[0][0]);
        }
    }


    protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName.Equals("del"))
        {
            string[] p_arr = e.CommandArgument.ToString().Split(',');
            string no = p_arr[0];
            int ID = TypeConvert.ToInt32(p_arr[1]);
            new Hongapo_Services.Product.ProductImage().Delete(no);
            new Hongapo_Services.Product.Comment().DeleteByPID(ID);
            bll.Delete(no);
            BindRepeter();
        }
    }

    /// <summary>
    /// 启用或者停用
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void linkButton_click(object sender, EventArgs e)
    {
        LinkButton btn = sender as LinkButton;
        int id = TypeConvert.ToInt32(btn.CommandName);
        int isopen = btn.Text == "发布" ? 1 : 0;
        bll.UpdateIsopen(id, isopen,UserID);
        BindRepeter();
    }
}
